package freejim.icu.highschoolhealthstatuspost.controller;


import freejim.icu.highschoolhealthstatuspost.dao.User;
import freejim.icu.highschoolhealthstatuspost.service.TCaptchaVerify;
import freejim.icu.highschoolhealthstatuspost.service.UserService;
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class Authcation {


    @Resource
    TCaptchaVerify tCaptchaVerify;

    @Resource
    UserService userService;

    @RequestMapping("/user/auth")
    @ResponseBody
    public Boolean userAuth(HttpServletResponse response,HttpServletRequest request){
        return true;
    }
    @RequestMapping("/admin/auth")
    @ResponseBody
    public Boolean adminAuth(HttpServletResponse response,HttpServletRequest request){
        return true;
    }

    @RequestMapping("/user/login_frontend")
    @CrossOrigin
    public String userLogin(){return "login_frontend";}

    @RequestMapping("/")
    public String homePage(){return "login_frontend";}

    @RequestMapping("/admin/login_backend")
    public String adminLogin(){return "login_backend";}

    @RequestMapping("/admin")
    public String admin(){return "admin";}
    @RequestMapping("/user")
    public String user(){return "user";}

    @RequestMapping("/verify")
    @ResponseBody
    public Object verify(HttpServletRequest request){
        String ticket = request.getParameter("ticket");
        String rand = request.getParameter("rand");
        int res = tCaptchaVerify.verifyTicket(ticket,rand);
        System.out.println(res);
        return res;
    }
    @RequestMapping("/admin/lockUser")
    @ResponseBody
    public Object lockUser(HttpServletRequest request){
        userService.lockUser(request);

        return "ok";
    }
    @RequestMapping("/admin/unLockUser")
    @ResponseBody
    public Object unLockUser(HttpServletRequest request){
        userService.unLockUser(request);
        return "ok";
    }


}
